﻿using System.Windows;
using YwangHRMSys.DAL;
using YwangHRMSys.Model;


namespace YwangHRMSys.UI.SystemMgr.CategoryMgr
    {
        /// <summary>
        ///     CategoryWindow.xaml 的交互逻辑
        /// </summary>
        public partial class CategoryWindowList : Window
            {

                public CategoryWindowList()
                {
                    InitializeComponent();
                }


                private void LoadData()
                {
                    var dal = new CategoryDAL();
                    DataGridCegoryList.ItemsSource = dal.ListAll();
                  
                }

                private void Window_Loaded( object sender, RoutedEventArgs e )
                {
                    CmbCategory.ItemsSource = new CategoryDAL().ListCategory();
                    LoadData();
                }

                /// <summary>
                ///     添加类别信息
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void BtnAdd_Click( object sender, RoutedEventArgs e )
                {

                    var win = new CategoryWindowEdit();
                    win.IsInsert = true;

                    if (win.ShowDialog() == true)
                        {
                            LoadData();
                        }

                }

                /// <summary>
                ///     编辑类别信息
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void BtnEdit_Click( object sender, RoutedEventArgs e )
                {
                    var model = (CategoryModel) DataGridCegoryList.SelectedItem;
                    if (model == null)
                        {
                            MessageBox.Show("请选择行！");
                            return;
                        }
                    var win = new CategoryWindowEdit();
                    win.IsInsert = false;
                    win.EditGuid = model.Id;
                    win.Category = CmbCategory.Text;
                    if (win.ShowDialog() == true)
                        {
                            LoadData();

                        }


                }

                private void BtnSearch_Click(object sender, RoutedEventArgs e)
                {

                    if (CkCategory.IsChecked==true)
                        {
                            string cmbcategory = CmbCategory.Text;
                          //  MessageBox.Show();
                            if (cmbcategory !=null)
                                {
                                       DataGridCegoryList.ItemsSource=    new CategoryDAL().GetByCategory(cmbcategory);

                                }
                          
                     
                        }  else
                                {
                                    LoadData();
                                }

                }

            }
    }